<template>
    <el-alert show-icon style="margin-bottom: 20px;" effect="dark" title="默认生成指定model层下所有的实体到数据库!"
        description="model层也不仅仅只有数据库的model,也许会有其他的,一般将其放到同一文件夹下,通过对应的命名空间过滤!" type="success" :closable="false" />

    <el-form :model="form" label-width="auto">

        <el-form-item label="Model层名称">
            <el-input v-model="form.modelName" placeholder="默认【VerEasy.Core.Models】" />
        </el-form-item>

        <el-form-item label="命名空间过滤">
            <el-input v-model="form.filterByNameSpace" placeholder="默认【ViewModels】" />
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit" :loading="loading">
                <template #icon>
                    <Icon icon="line-md:document-code"></Icon>
                </template>
                生成
            </el-button>
        </el-form-item>

    </el-form>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { Icon } from '@iconify/vue';
import { CreateDataTable } from '../../../utils/api';

const loading = ref(false)
const form = reactive({
    modelName: '',
    filterByNameSpace: ''
})

const onSubmit = async () => {
    ElMessageBox.confirm(
        '是否生成数据库表?',
        '提示',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    )
        .then(async () => {
            loading.value = true;
            try {
                await CreateDataTable(form.modelName, form.filterByNameSpace);
            } finally {
                loading.value = false;
            }
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '取消生成',
            })
        })
}
</script>